
package JET.Frames.DataModels;

import JET.Centers.ControlCenter;
import JET.Scene;
import java.util.ArrayList;
import javax.swing.ListModel;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;

/**
 *
 * @author 057Ry
 */
public class ScriptsListModel implements ListModel {

    static final ControlCenter CC = ControlCenter.getInstance();
    private ArrayList<ListDataListener> listeners;
    private Scene scene;

    public ScriptsListModel() {
        listeners = new ArrayList<ListDataListener>();
    }

    public void setScene(Scene s) {
        scene = s;
    }
    
    public int getSize() {
        if (scene!=null)
            return scene.SC.getScriptsCount();
        else
            return 0;
    }

    public Object getElementAt(int index) {
        if (scene!=null)
            return scene.SC.getScript(index);
        else
            return null;
    }

    public void fireScriptsListChanged() {
        for(ListDataListener l : listeners)
            l.contentsChanged( new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, 0, getSize()-1));
    }

    public void addListDataListener(ListDataListener l) {
        listeners.add(l);
    }

    public void removeListDataListener(ListDataListener l) {
        listeners.remove(l);
    }
}